using System;
using System.Collections.Generic;
using CMS.Core.DataInterfaces;
using CMS.Core.Domain;

namespace CMS.Data
{
    public class LoaiDonDao : AbstractNHibernateDao<LoaiDon, System.Int32>, ILoaiDonDao
    {
        #region Create Instance
        private static LoaiDonDao instance = null;
        public static LoaiDonDao Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new LoaiDonDao();
                }
                return instance;
            }
        }
        #endregion     

        public byte GetMaxSTT()
        {
            byte result = 1;
            try
            {
                Object obj = null;
                String strSQL = @"Select Max(o.STT)from LoaiDon o ";
                obj = NHibernateSessionManager.Instance.GetSession().CreateQuery(strSQL)
                    .UniqueResult();
                if (obj != null)
                {
                    result = Convert.ToByte(obj);
                    result += 1;
                }
                return result;
            }
            catch
            {
                return result;
            }
        }

        public List<LoaiDon> GetAllHasOrderBy(bool TrangThai)
        {
            try
            {
                String strQuery = @"From LoaiDon o Where o.TrangThai =:TrangThai Order by o.STT, o.TenLoaiDon";
                List<LoaiDon> Result = NHibernateSessionManager.Instance.GetSession().CreateQuery(strQuery)
                        .SetParameter("TrangThai", TrangThai)
                        .List<LoaiDon>() as List<LoaiDon>;
                return Result;
            }
            catch
            {
                return new List<LoaiDon>();
            }
        }
    }
}
